package com.lscl.rabbitmq;

import com.rabbitmq.client.*;

import java.io.IOException;

public class Consumer11_Header {
    public static void main(String[] args) throws Exception {
        // 创建连接和频道
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.40.141");
        factory.setPort(5672);
        factory.setUsername("lscl");
        factory.setPassword("admin");
        factory.setVirtualHost("/lscl");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.basicConsume("test_header_queue", true, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {

                System.out.println("body：" + new String(body));
            }
        });

    }
}
